package com.ifacebox.client.tools.utils;

import java.io.File;
import java.net.URL;
import java.net.URLDecoder;

/**
 * @author Znn
 * @date 2021/1/17 21:34
 */
public class PathUtils {
    public static final URL PATH_URL = PathUtils.class.getProtectionDomain().getCodeSource().getLocation();
    public static final String PATH_JAR = ".jar";
    public static final String UTF_8 = "UTF-8";

    public static String getLocalPath() {
        return getLocalPathFile().getAbsolutePath();
    }

    public static File getLocalPathFile() {
        String path;
        try {
            path = URLDecoder.decode(PATH_URL.getPath(), UTF_8);
        } catch (Exception e) {
            path = PATH_URL.getPath();
        }
        if (path.toLowerCase().endsWith(PATH_JAR)) {
            path = path.substring(0, path.lastIndexOf("/") + 1);
        }
        return new File(path);
    }

}
